<template>
  <div>
    <h2>我的吐槽:</h2>
    <hr>
    <div>
      <a-list item-layout="horizontal" :data-source="data">
        <template #renderItem="{ item }">
          <a-list-item>
            <template #actions>
              <a @click="viewTalk(item)" key="list-loadmore-view">查看</a>
              <a @click="deleteTalk(item)" key="list-loadmore-delete">删除</a>
            </template>
            <a-list-item-meta
                :description="item.content">
              <template #title>
                <h4> {{ item.userNick }}</h4>
              </template>
              <template #avatar>
                <a-avatar :size="48" :src="item.userAva"/>
              </template>
            </a-list-item-meta>
          </a-list-item>
        </template>
      </a-list>
      <a-pagination v-model:current="pageObj.page" v-model:page-size="pageObj.limit" :total="pageObj.total"
                    show-less-items @change="pageChange"/>
      <user-self-talk ref="userSelfTalkChild"
                      @closeUserSelfTalk="closeUserSelfTalk"
                      :parent-visible="childVisible"/>

    </div>
  </div>
</template>

<script>
import $httpPost from "@/api/myAxios/PostApi";
import userSelfTalk from "@/components/user/userSelfTalk";
import {message} from "ant-design-vue";

export default {
  name: "myTalkList",
  components: {
    userSelfTalk
  },
  data() {
    return {
      childVisible: false,
      data: [],
      pageObj: {
        page: 1,
        limit: 5,
        total: 0
      }
    }
  },
  methods: {
    pageChange(current, pageSize) {
      this.initData()
    },
    closeUserSelfTalk() {
      this.childVisible = false
    },
    viewTalk(item) {
      this.childVisible = true
      this.$refs.userSelfTalkChild.initData(item.id)
    },
    deleteTalk(item){
      let id = item.id;
      $httpPost("xy/talk/selfDeleteTalkById",id).then(res=>{
        if (res.data.code==0){
          message.success("删除成功")
        }else {
          message.warn("服务器繁忙....")
        }
        this.initData()
      })
    },
    initData() {
      $httpPost("xy/talk/getUserTalkList", this.pageObj).then(async res => {
        this.data = await res.data.pageData.list
        this.pageObj.total = res.data.pageData.totalCount
      })
    }
  },
  created() {
    this.initData()
  }
}
</script>

<style scoped>

</style>